package com.chen.user.controller;


import com.chen.user.common.Result;
import com.chen.user.entity.HotelRoom;
import com.chen.user.response.HomeRoomCardResponse;
import com.chen.user.service.HomeCardService;
import com.chen.user.service.HotelRoomInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin(origins = "http://localhost:8080")
@RequestMapping("/user")
public class HomeRoomCardController {

    @Autowired
    private HomeCardService homeCardService;

    @Autowired
    private HotelRoomInfoService hotelRoomInfoService;

    /**
     * 卡片展示
     * @param pageNumber
     * @param pageSize
     * @return
     */
    @GetMapping("/selectCategoryPage")
    public Result<PageInfo> selectCategoryPage(@RequestParam("category") String categoryName) {
        PageHelper.startPage(1, 10);

       List<HomeRoomCardResponse> homeRoomCardResponseList= homeCardService.selectCategoryPage(categoryName);
       return Result.success(new PageInfo<>(homeRoomCardResponseList));

    }




    @GetMapping("/getHomeCardPage")
    public Result<PageInfo> getHomeCardPage(@RequestParam(defaultValue = "0") Integer pageNumber,
                                            @RequestParam(defaultValue = "10") Integer pageSize) {
        PageHelper.startPage(pageNumber,pageSize);
      List<HomeRoomCardResponse> homeRoomCardResponseList= homeCardService.getHomeCardPage();
      return Result.success(new PageInfo<>(homeRoomCardResponseList));

    }
    /**
     * 房间详情页接口
     */

    @GetMapping("/getRoomInfoById/{roomId}")
    public Result<HotelRoom> getRoomInfoById(@PathVariable Integer roomId) {
      HotelRoom hotelRoom= hotelRoomInfoService.getHotelRoomById(roomId);
      return Result.success(hotelRoom);

    }


}
